import { _decorator, Component, Node, Label, EventTouch, RichText, find } from 'cc';
import { losChannel } from '../../app/Script/SDK/losChannel';
import { App } from '../../app/App';

const { ccclass, property } = _decorator;

// import { prv } from "./prv";

@ccclass('PrivacyWin')
export default class privacyWin extends Component {
    @property(Node)
    public txt_main: Node = null;
    @property(Node)
    public bt_agree: Node = null;
    @property(Node)
    public bt_reject: Node = null;
    @property(Node)
    public win2: Node = null;
    @property(RichText)
    public txt: RichText = null;
    @property(Node)
    public bt_next: Node = null;
    @property(Node)
    public bt_pre: Node = null;
    @property(Node)
    public closeNode: Node = null;
    @property(Node)
    public bt_type1: Node = null;
    @property(Node)
    public bt_type2: Node = null;

    @property(RichText)
    public richText!: RichText;

    /** 隐私政策还是用户协议,0为前者，1为后者 */
    pType: number = 0;
    /** 同意后是否走toMain */
    isToMain: boolean = true;
    onLoad() {

        this.closeNode.on(Node.EventType.TOUCH_END, (e: EventTouch) => {
            this.closeDetail();
        });

        this.bt_pre.on(Node.EventType.TOUCH_END, (e: EventTouch) => {
            this.txt.string = losChannel.instance().privacyPrePage(this.pType);
        });

        this.bt_next.on(Node.EventType.TOUCH_END, (e: EventTouch) => {
            this.txt.string = losChannel.instance().privacyNextPage(this.pType);
        });

        this.bt_type1.on(Node.EventType.TOUCH_END, (e: EventTouch) => {
            this.pType = 0;
            this.txt.string = losChannel.instance().privacyPage1(this.pType);
        });
        this.bt_type2.on(Node.EventType.TOUCH_END, (e: EventTouch) => {
            this.pType = 1;
            this.txt.string = losChannel.instance().privacyPage1(this.pType);
        });


        this.txt.string = losChannel.instance().privacyPage1(this.pType);

        this.bt_agree.on(Node.EventType.TOUCH_END, (e: EventTouch) => {
            this.agree();
        });

        this.bt_reject.on(Node.EventType.TOUCH_END, (e: EventTouch) => {
            this.node.active = false;
            losChannel.instance().privacyReject();
            losChannel.instance().exit();
        });

        this.txt_main.on(Node.EventType.TOUCH_END, (e: EventTouch) => {
            this.win2.active = true;
        });
        this.win2.active = false;
        this.txt_main.getComponent(RichText).string = '我同意<color=#f55b0e>《用户协议》</c>和<color=#f55b0e>《隐私政策》</c>';

    }
    closeDirectly = false
    showWin2() {
        this.win2.active = true
        this.closeDirectly = true
    }
    closeDetail() {
        this.win2.active = false;
        if (this.closeDirectly) {
            this.node.active = false
            this.node.destroy()
        }
    }
    agree() {
        losChannel.instance().privacyAgree();
        find('UICanvas').getComponent(App).loading()
        this.node.destroy()

    }
}

